package crmdna.client.isha;

import java.util.List;

import javax.inject.Named;

import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiMethod.HttpMethod;
import com.google.appengine.api.users.User;

import crmdna.attendance.AttendanceFactory;
import crmdna.attendance.CheckInMemberProp;
import crmdna.attendance.IAttendance;
import crmdna.common.APIResponse;
import crmdna.common.APIResponse.Status;
import crmdna.common.Utils;

@Api(name = "isha")
public class IshaAttendanceApi {

	@ApiMethod(path = "getMembersForCheckIn", httpMethod = HttpMethod.GET)
	public APIResponse getMembersForCheckIn(
			@Named("searchStr") String searchStr,
			@Named("programId") long programId,
			@Named("sessionDateYYYYMMDD") int sessionDateYYYYMMDD,
			@Named("maxResultsSize") Integer maxResultsSize, User user) {
		try {

			if (maxResultsSize == null)
				maxResultsSize = 25; // default value

			IAttendance impl = AttendanceFactory.getImpl("isha");

			List<CheckInMemberProp> checkInMemberProps = impl
					.getMembersForCheckIn(searchStr, programId,
							sessionDateYYYYMMDD, 25, Utils.getLoginEmail(user));

			return new APIResponse(Status.SUCCESS, checkInMemberProps);

		} catch (Exception ex) {
			return new APIResponse(ex);
		}
	}
}
